<script setup>
import {
    Edit,
    Delete
} from '@element-plus/icons-vue'
import { ref } from 'vue'
const outbound = ref([

])
//声明一个异步函数
import {getOutboundService,upDateOutboundService} from '@/api/outbound.js'
import { ElMessage } from 'element-plus';
const outboundList = async()=>{
    let result = await getOutboundService();
    outbound.value = result.data;
}
outboundList();


const dialogVisible = ref(false)

//添加出库数据模型
const outboundModel = ref({
    sailingDay: '',
    outboundQty: '',
    outboundTon: ''
})
//添加出库表单校验
const rules = {
    sailingDay: [
        { required: true, message: '请输入开船日', trigger: 'blur' },
    ],
    outboundQty: [
        { required: true, message: '请输入出库件数', trigger: 'blur' },
    ],    
    outboundTon: [
        { required: true, message: '请输入出库吨数', trigger: 'blur' },
    ]
}
import dayjs from 'dayjs';
const upDateOutbound = async()=>{
    let sailingDay = dayjs(outboundModel.value.sailingDay).toDate();
    let result = await upDateOutboundService(sailingDay,outboundModel.value.outboundQty,outboundModel.value.outboundTon);
    ElMessage.success(result.message? result.message:'添加成功')
    outboundList();
    dialogVisible.value = false;
}

</script>
<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>出库管理</span>
                <div class="extra">
                    <el-button type="primary" @click="dialogVisible = true">添加出库</el-button>
                </div>
            </div>
        </template>
        <el-table :data="outbound" style="width: 100%">
            <el-table-column label="序号" width="100" type="index"> </el-table-column>
            <el-table-column label="开船日" prop="sailingDay"></el-table-column>
            <el-table-column label="出库件数" prop="outboundQty"></el-table-column>
            <el-table-column label="出库吨数" prop="outboundTon"></el-table-column>
            <template #empty>
                <el-empty description="没有数据" />
            </template>
        </el-table>

        <!-- 添加分类弹窗 -->
        <el-dialog v-model="dialogVisible" title="添加出库" width="30%">
            <el-form :model="outboundModel" :rules="rules" label-width="100px" style="padding-right: 30px">
                <el-form-item label="开船日" prop="sailingDay">
                    <el-date-picker v-model="outboundModel.sailingDay" type="date" placeholder="选择日期" style="width: 80%"></el-date-picker>
                </el-form-item>
                <el-form-item label="出库件数" prop="outboundQty">
                    <el-input v-model="outboundModel.outboundQty" minlength="1" maxlength="15"></el-input>
                </el-form-item>
                <el-form-item label="出库吨数" prop="outboundTon">
                    <el-input v-model="outboundModel.outboundTon" minlength="1" maxlength="15"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="dialogVisible = false">取消</el-button>
                    <el-button type="primary" @click="upDateOutbound"> 确认 </el-button>
                </span>
            </template>
        </el-dialog>        
    </el-card>
</template>

<style lang="scss" scoped>
.page-container {
    min-height: 100%;
    box-sizing: border-box;

    .header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
}
</style>